package com.hubiao.basics.pattern.observice;

import java.util.Observable;

/**
 * JDK提供的一种观察者的实现方式，被观察者
 * Created by jackhu on 2019/3/17.
 */
public class GPer extends Observable {

    private static GPer gper = null;
    private String name = "GPer生态圈";

    private GPer() {
    }

    //单例的方式
    public static GPer getInstance() {
        if (null == gper) {
            gper = new GPer();
        }
        return gper;
    }

    public String getName() {
        return name;
    }


    /**
     * 自定义发送方法
     *
     * @param question
     */
    public void publishQuestion(Question question) {
        System.out.println( question.getUserName() + "在" + this.name + "上提交了一个问题。" );
        //设置被观察者做出了修改修改了
        setChanged();
        //唤醒全部观察者
        notifyObservers( question );
    }
}
